package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.enums.WalletChannelEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.WithdrawBankCard;
import com.sc.nft.mapper.WithdrawBankCardMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 提现绑卡表(sc_withdraw_bank_card)数据DAO
 *
 * @author zxy
 * @since 2022-12-31 19:38:43
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class WithdrawBankCardDao extends ServiceImpl<WithdrawBankCardMapper, WithdrawBankCard> {

    public WithdrawBankCard findUserCard(Long userId, String cardNo, WalletChannelEnum channel){
        LambdaQueryWrapper<WithdrawBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WithdrawBankCard::getUserId,userId);
        wrapper.eq(WithdrawBankCard::getChannel,channel);
        wrapper.eq(WithdrawBankCard::getBankCardNo,cardNo);
        wrapper.eq(WithdrawBankCard::getStatus,true);
        return getOne(wrapper);
    }

    public void deleteByUserId(Long userId){
        LambdaUpdateWrapper<WithdrawBankCard> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(WithdrawBankCard::getUserId,userId);
        remove(wrapper);
    }
    public WithdrawBankCard getByBindId(Long bindId){
        LambdaQueryWrapper<WithdrawBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WithdrawBankCard::getBindId,bindId);
        return  getOne(wrapper);
    }

    public WithdrawBankCard findByCard(String cardNo){
        LambdaQueryWrapper<WithdrawBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WithdrawBankCard::getBankCardNo,cardNo);
        wrapper.eq(WithdrawBankCard::getStatus,true);
        return getOne(wrapper);
    }
    public List<WithdrawBankCard> getByUserId(Long userId){
        LambdaQueryWrapper<WithdrawBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WithdrawBankCard::getUserId,userId);
        wrapper.eq(WithdrawBankCard::getStatus,true);
        return list(wrapper);
    }


    public List<WithdrawBankCard> getByUserIdAndChannel(Long userId,WalletChannelEnum channel){
        LambdaQueryWrapper<WithdrawBankCard> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WithdrawBankCard::getUserId,userId);
        wrapper.eq(WithdrawBankCard::getChannel,channel);
        wrapper.eq(WithdrawBankCard::getStatus,true);
        return list(wrapper);
    }
}